package org.itfarmer.service.impl;

import java.util.List;

import org.itfarmer.dao.SalaryinfoDAO;
import org.itfarmer.dao.pojo.Salaryinfo;
import org.itfarmer.service.SalaryinfoService;

public class SalaryinfoServiceImpl implements SalaryinfoService {

	private SalaryinfoDAO salaryinfoDAO;
	
	/*
	 * (non-Javadoc)
	 * @see org.itfarmer.service.BaseService#countService()
	 */
	public Integer countService() {
		Integer rows = salaryinfoDAO.count(Salaryinfo.class);
		return rows;
	}
	
	/*
	 * (non-Javadoc)
	 * @see org.itfarmer.service.SalaryinfoService#searchAll(java.lang.Integer, java.lang.Integer)
	 */
	public List<Salaryinfo> searchAll(Integer pageNow, Integer pageSize) {
		Integer firstRow = (pageNow - 1) * pageSize;
		Integer maxRow = pageSize;
		List<Salaryinfo> list = salaryinfoDAO.read(Salaryinfo.class, firstRow, maxRow);
		return list;
	}
	
	/*
	 * (non-Javadoc)
	 * @see org.itfarmer.service.SalaryinfoService#searchByWorkid(java.lang.Integer)
	 */
	public Salaryinfo searchByWorkid(Integer workid) {
		if (workid == null) {
			return null;
		}
		Salaryinfo salaryinfo = salaryinfoDAO.readByWorkid(workid);
		return salaryinfo;
	}
	
	/*
	 * (non-Javadoc)
	 * @see org.itfarmer.service.SalaryinfoService#insertSalary(org.itfarmer.dao.pojo.Salaryinfo)
	 */
	public boolean insertSalary(Salaryinfo salaryinfo) {
		if (salaryinfo == null) {
			return false;
		}
		Integer pk = salaryinfoDAO.create(salaryinfo);
		return pk == null || pk <= 0 ? false : true;
	}
	
	/*
	 * (non-Javadoc)
	 * @see org.itfarmer.service.SalaryinfoService#makeFinal(java.lang.Integer)
	 */
	public boolean makeFinal(Integer said) {
		if (said == null) {
			return false;
		}
		Salaryinfo salary = salaryinfoDAO.read(Salaryinfo.class, said);
		
		double finalsalary = salary.getSalary() - salary.getAbsence() * 10 + salary.getBonus();
		salary.setFinalsalary(finalsalary);
		boolean checked = salaryinfoDAO.update(salary);
		return checked;
	}
	
	/*
	 * (non-Javadoc)
	 * @see org.itfarmer.service.SalaryinfoService#makeSend(java.lang.Integer)
	 */
	public boolean makeSend(Integer said) {
		if (said == null) {
			return false;
		}
		Salaryinfo salary = salaryinfoDAO.read(Salaryinfo.class, said);
		salary.setIssent(1);
		boolean checked = salaryinfoDAO.update(salary);
		return checked;
	}

	public SalaryinfoDAO getSalaryinfoDAO() {
		return salaryinfoDAO;
	}

	public void setSalaryinfoDAO(SalaryinfoDAO salaryinfoDAO) {
		this.salaryinfoDAO = salaryinfoDAO;
	}

	
}
 